package com.collect.zambia.zhiScene.zhiWidget.zhiTabItemColumn;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.collect.zambia.R;

public class ZHITabItemColumn3View extends LinearLayout {

    private final Context mContext;
    private String ztic3Text1 = "";
    private int ztic3Text1Color = -1;
    private String ztic3Text2 = "";
    private int ztic3Text2Color = -1;
    private String ztic3Text3 = "";
    private int ztic3Text3Color = -1;

    private String ztic3Detail1 = "";
    private int ztic3Detail1Color = -1;
    private String ztic3Detail2 = "";
    private int ztic3Detail2Color = -1;
    private String ztic3Detail3 = "";
    private int ztic3Detail3Color = -1;

    private int ztic3SepLineColor = -1;

    private TextView tv_tabitem_title1;
    private TextView tv_tabitem_title2;
    private TextView tv_tabitem_title3;
    private TextView tv_tabitem_detail1;
    private TextView tv_tabitem_detail2;
    private TextView tv_tabitem_detail3;

    public ZHITabItemColumn3View(Context context) {
        this(context, null);
    }

    public ZHITabItemColumn3View(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ZHITabItemColumn3View(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ZHITabItemColumn3View);
        ztic3Text1 = typedArray.getString(R.styleable.ZHITabItemColumn3View_ztic3Text1);
        ztic3Text1Color = typedArray.getColor(R.styleable.ZHITabItemColumn3View_ztic3Text1Color, ContextCompat.getColor(context, R.color.theme_black_0));
        ztic3Text2 = typedArray.getString(R.styleable.ZHITabItemColumn3View_ztic3Text2);
        ztic3Text2Color = typedArray.getColor(R.styleable.ZHITabItemColumn3View_ztic3Text2Color, ContextCompat.getColor(context, R.color.theme_black_0));
        ztic3Text3 = typedArray.getString(R.styleable.ZHITabItemColumn3View_ztic3Text3);
        ztic3Text3Color = typedArray.getColor(R.styleable.ZHITabItemColumn3View_ztic3Text3Color, ContextCompat.getColor(context, R.color.theme_black_0));

        ztic3Detail1 = typedArray.getString(R.styleable.ZHITabItemColumn3View_ztic3Detail1);
        ztic3Detail1Color = typedArray.getColor(R.styleable.ZHITabItemColumn3View_ztic3Detail1Color, ContextCompat.getColor(context, R.color.theme_green_0));
        ztic3Detail2 = typedArray.getString(R.styleable.ZHITabItemColumn3View_ztic3Detail2);
        ztic3Detail2Color = typedArray.getColor(R.styleable.ZHITabItemColumn3View_ztic3Detail2Color, ContextCompat.getColor(context, R.color.theme_green_0));
        ztic3Detail3 = typedArray.getString(R.styleable.ZHITabItemColumn3View_ztic3Detail3);
        ztic3Detail3Color = typedArray.getColor(R.styleable.ZHITabItemColumn3View_ztic3Detail3Color, ContextCompat.getColor(context, R.color.theme_green_0));

        ztic3SepLineColor = typedArray.getColor(R.styleable.ZHITabItemColumn3View_ztic3SepLineColor, ContextCompat.getColor(context, R.color.theme_color_0));

        typedArray.recycle();

        initView();
    }

    /**
     * 初始化组件数据
     *
     * @type method
     * @author liwenjie
     * @creatTime 2019-10-25 19:43
     */
    private void initView() {
        View mView = View.inflate(mContext, R.layout.view_tabitem_column3, this);
        tv_tabitem_title1 = mView.findViewById(R.id.tv_tabitem_title1);
        tv_tabitem_title2 = mView.findViewById(R.id.tv_tabitem_title2);
        tv_tabitem_title3 = mView.findViewById(R.id.tv_tabitem_title3);
        tv_tabitem_detail1 = mView.findViewById(R.id.tv_tabitem_detail1);
        tv_tabitem_detail2 = mView.findViewById(R.id.tv_tabitem_detail2);
        tv_tabitem_detail3 = mView.findViewById(R.id.tv_tabitem_detail3);

        View v_line_1 = mView.findViewById(R.id.v_line_1);
        View v_line_2 = mView.findViewById(R.id.v_line_2);

        tv_tabitem_title1.setText(ztic3Text1);
        tv_tabitem_title1.setTextColor(ztic3Text1Color);
        tv_tabitem_title2.setText(ztic3Text2);
        tv_tabitem_title2.setTextColor(ztic3Text2Color);
        tv_tabitem_title3.setText(ztic3Text3);
        tv_tabitem_title3.setTextColor(ztic3Text3Color);

        tv_tabitem_detail1.setText(ztic3Detail1);
        tv_tabitem_detail1.setTextColor(ztic3Detail1Color);
        tv_tabitem_detail2.setText(ztic3Detail2);
        tv_tabitem_detail2.setTextColor(ztic3Detail2Color);
        tv_tabitem_detail3.setText(ztic3Detail3);
        tv_tabitem_detail3.setTextColor(ztic3Detail3Color);

        v_line_1.setBackgroundColor(ztic3SepLineColor);
        v_line_2.setBackgroundColor(ztic3SepLineColor);

    }

    public void setText(String text, int index) {
        if (0 == index) {
            ztic3Text1 = text;
            tv_tabitem_title1.setText(text);
        } else if (1 == index) {
            ztic3Text2 = text;
            tv_tabitem_title2.setText(text);
        } else if (2 == index) {
            ztic3Text3 = text;
            tv_tabitem_title3.setText(text);
        }
    }

    public void setDetail(String text, int index) {
        if (0 == index) {
            ztic3Detail1 = text;
            tv_tabitem_detail1.setText(text);
        } else if (1 == index) {
            ztic3Detail2 = text;
            tv_tabitem_detail2.setText(text);
        } else if (2 == index) {
            ztic3Detail3 = text;
            tv_tabitem_detail3.setText(text);
        }
    }

}
